﻿Ext.namespace('EHSubmit.BBS.AddRes');



//------------发表新帖子-----------
EHSubmit.BBS.AddRes.SendRes = function AendRes() {
    var frm = Ext.getCmp('AddResForm');
    if (frm.getForm().isValid()) { // 验证表单
        var body = Ext.getCmp('innerForm_down').getValue();
        //aid自增,其他服务器端处理
        var Restore = {
            ResAnnID: AnnID,
            RestoreBody: body,
            RestoreUID: CurrentUser.ID,
            RestoreName: CurrentUser.Name
        }
        var ResJson = Ext.util.JSON.encode(Restore);

        frm.getForm().submit({     // 提交
            url: EHSubmit.ajaxRoot + 'BBSHandler.ashx?op=addRes',
            waitTitle: '等待',
            waitMsg: '正在发送，请稍后...',
            method: 'POST',
            params: {
                Res: ResJson
            },
            success: function(form, action) {
                var successed = action.result.success;
                if (successed) {
                    ///////////////  提交成功处理  ///////////////////
                    Ext.MessageBox.alert('提示', action.result.msg);
                    Ext.getCmp('ViewGrid').store.reload();
                }
                else {
                    Ext.MessageBox.alert('失败', '信息:' + action.result.msg);
                }
            },
            failure: function(form, action) {
                var errmsg = action.result.msg;
                Ext.MessageBox.alert('错误', errmsg);
            }   // failure  
        });
        //-----------关闭发件窗口------------
        var thisWin = Ext.getCmp('addResWin');
        thisWin.close();

    }
};


//---------------留言主窗口的上部----------
EHSubmit.BBS.AddRes.innerForm_up = {
    id: 'innerForm_up',
    xtype: 'fieldset',
    flex: 0.25,
    //height:80,
    labelAlign: 'center',
    //anchor:'100%',
    defaults: { width: 400 },
    defaultType: 'textfield',
    items: [{
        id: 'AddResTitle',
        fieldLabel: '主题',
        //name: 'title',
        readOnly: true,
        value: '回复：'
    }, {
        id: 'AddResTitle_Name',
        fieldLabel: '提问者',
        //name: 'title',
        readOnly: true,
        value: ''
    }]
};

        //----------------留言主窗口的下部-------------
    EHSubmit.BBS.AddRes.innerForm_down = {
        xtype: 'panel',
        flex: 0.9,
        layout: 'fit',
        items: [{
            id: 'innerForm_down',
            xtype: 'htmleditor',
            //name:'content',
            emptyText: '留言内容',
            flex: 1
        }]


        };

        //-------------留言主窗口----------
        EHSubmit.BBS.AddRes.innerForm = {
            xtype: 'form',
            id: 'AddResForm',
            layout: {
                type: 'vbox',
                padding: '2',
                align: 'stretch'
            },
            border: false,
            frame: true,
            monitorValid: true,
            //-------中间部分----------
            items: [EHSubmit.BBS.AddRes.innerForm_up, EHSubmit.BBS.AddRes.innerForm_down]

        };

    EHSubmit.BBS.AddRes.window = {
        id: 'addResWin',
        title: '发表留言',
        //xtype:'window',
        width: 700,
        height: 450,
        plain: true,
        border: false,
        layout: 'fit',
        modal: true,
        listeners: {
        render: function() {
                //Ext.getCmp('AddResTitle').setValue('回复：' + Topic);
            }
        },

        //-------topbar-------
        tbar: [{
            text: '发布',
            tooltip: '发布',
            iconCls: 'icon-send',
            handler: EHSubmit.BBS.AddRes.SendRes
        }, '-', {
            text: '关闭',
            tooltip: '关闭',
            iconCls: 'close',
            handler: function() {
                var addResWin = Ext.getCmp('addResWin');
                addResWin.close();
            }
        }],

            items: [EHSubmit.BBS.AddRes.innerForm],

            //-------footbar--------------
            fbar: [{
                text: '发表',
                tooltip: '发表',
                iconCls: 'icon-send',     //图标引用需写在css中
                handler: EHSubmit.BBS.AddRes.SendRes
            }, '-', {
                text: '关闭',
                tooltip: '关闭',
                iconCls: 'close',
                handler: function() {
                    //----关闭当前窗口---------
                    var addResWin = Ext.getCmp('addResWin');
                    addResWin.close();
                }
        }]
 };